-- app to expected ime config
local bundleids = {
	-- "net.kovidgoyal.kitty",
	"com.tencent.xWeChat",
	"com.tencent.xinWeChat",
	"com.tencent.xinWeChat2",
	"com.tencent.qq",
	"com.mchat.tea",
}

-- local function updateFocusAppInputMethod()
-- 	local app_bundleid = hs.window.frontmostWindow():application():bundleID()
-- 	for _, bundleid in pairs(bundleids) do
-- 		if app_bundleid == bundleid then
-- 			hs.keycodes.currentSourceID("com.apple.inputmethod.SCIM.Shuangpin")
-- 			return
-- 		end
-- 	end
-- 	hs.keycodes.currentSourceID("com.apple.keylayout.ABC")
-- end

-- helper hotkey to figure out the app path and name of current focused window
-- hs.hotkey.bind({ "cmd", "shift" }, ".", function()
-- 	hs.alert.show(
-- 		"App path:        "
-- 			.. hs.window.focusedWindow():application():path()
-- 			.. "\n"
-- 			.. "App name:      "
-- 			.. hs.window.focusedWindow():application():name()
-- 			.. "\n"
-- 			.. "ID:            "
-- 			.. hs.window.focusedWindow():application():bundleID()
-- 			.. "\n"
-- 			.. "IM source id:  "
-- 			.. hs.keycodes.currentSourceID()
-- 	)
-- end)
--
-- -- Handle cursor focus and application's screen manage.
-- local function applicationWatcher(appName, eventType, appObject)
-- 	if
-- 		eventType == hs.application.watcher.activated
-- 		or eventType == hs.application.watcher.launching
-- 		or eventType == hs.application.watcher.launched
-- 	then
-- 		hs.alert.show(appName)
-- 		updateFocusAppInputMethod()
-- 	end
-- end

-- appWatcher = hs.application.watcher.new(applicationWatcher)
-- appWatcher:start()

local watcher = require("modules.lib")

-- Register multiple callbacks
watcher.addCallback(function(win)
	-- hs.alert.show("Callback 1 - App: " .. (win:application():bundleID() or "Unknown"))
	for _, bundleid in pairs(bundleids) do
		if win:application():bundleID() == bundleid then
			hs.keycodes.currentSourceID("com.apple.inputmethod.SCIM.Shuangpin")
			return
		end
	end
	hs.keycodes.currentSourceID("com.apple.keylayout.ABC")
end)

watcher.start()
